import { ref } from "vue";
import { CesiumViewer } from "@/lib";

export function useMapViewer() {
  const cesiumViewer = ref<CesiumViewer | null>(null);

  const initViewer = (container: HTMLElement, options: any = {}) => {
    cesiumViewer.value = new CesiumViewer(container, {
      timeline: true,
      animation: true,
      baseLayerPicker: false,
      fullscreenButton: true,
      vrButton: false,
      geocoder: false,
      homeButton: false,
      infoBox: false,
      sceneModePicker: false,
      selectionIndicator: false,
      navigationHelpButton: false,
      navigationInstructionsInitiallyVisible: false,
      ...options,
    });
    // 设置时钟
    // cesiumViewer.value.setClock({
    //   startTime: new Date().getTime(),
    //   endTime: new Date().getTime() + 1000 * 60 * 60,
    //   speedMultiplier: 1,
    //   loop: 1,
    // });
    // 设置帧率显示状态
    // cesiumViewer.value.viewer!.scene.debugShowFramesPerSecond = true;
  };

  const destroyViewer = () => {
    if (cesiumViewer.value) {
      cesiumViewer.value.destroy();
      cesiumViewer.value = null;
    }
  };

  return {
    cesiumViewer,
    initViewer,
    destroyViewer,
  };
}
